package top.lyunz.lucky.hr.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import top.lyunz.lucky.hr.bean.engageMajorRelease;
import top.lyunz.lucky.hr.service.engageMajorReleaseService;
import top.lyunz.lucky.hr.tools.SimpleResult;

@Controller
public class engageMajorReleaseController {
	@Autowired
	private engageMajorReleaseService engageMajorReleaseService;
	@RequestMapping("/engageMajorReleaseAdd")
	public String engageMajorReleaseAdd(engageMajorRelease engageMajorRelease,HttpServletResponse response) {
		if(!engageMajorReleaseService.engageMajorReleaseAdd(engageMajorRelease)) {
			try {
				PrintWriter writer = response.getWriter();
				writer.print("<script type='text/javascript'>alert('添加失败，请联系站内管理员！');location.href('/recruit/toresumeRegister');</script>");
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
		}
		return "redirect:/engageMajorReleaseGetAll";
	}
	@RequestMapping("/engageMajorReleaseGetAll")
	public String engageMajorReleaseGetAll(Model model) {
		model.addAttribute("arr", engageMajorReleaseService.engageMajorReleaseGetAll());
		return "page/recruit/position/position_change_update";
	}
	@RequestMapping("/engageMajorReleaseDel/{id}")
	public void engageMajorReleaseDel(@PathVariable("id") int id,HttpServletResponse response) throws Exception {
		response.setContentType("text/html;charset=utf-8");
		PrintWriter writer = response.getWriter();
		if (engageMajorReleaseService.engageMajorReleaseDel(id)) {
			response.sendRedirect("/engageMajorReleaseGetAll");
		}else {
			writer.print("<script type='text/javascript'>alert('删除失败，请联系站内管理员！');location.href('engageMajorReleaseGetAll');</script>");
		}
	}
	@RequestMapping("/engageMajorReleaseGetByid/{id}")
	public String engageMajorReleaseGetByid(Model model,@PathVariable("id") int id) {
		engageMajorRelease arr = engageMajorReleaseService.engageMajorReleaseGetByid(id);
		model.addAttribute("a", arr);
		return "page/recruit/position/position_release_change";
	}
	@RequestMapping("/engageMajorReleaseUpd")
	public String engageMajorReleaseUpd(engageMajorRelease engageMajorRelease,HttpServletResponse response) {
		if(!engageMajorReleaseService.engageMajorReleaseUpd(engageMajorRelease)) {
			try {
				PrintWriter writer = response.getWriter();
				writer.print("<script type='text/javascript'>alert('修改失败，请联系站内管理员！');location.href('/configFileFirstkind/getConfigFileFirstkind');</script>");
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
		}
		return "redirect:/engageMajorReleaseGetAll";
	}
	@RequestMapping("/engageMajorReleaseGetAllfuhe")
	public String engageMajorReleaseGetAllfuhe(Model model) {
		model.addAttribute("arr", engageMajorReleaseService.engageMajorReleaseGetAll());
		return "page/recruit/position/position_release_search";
	}
}
